import Cocoa

enum TextAlignment{
    case left
    case right
    case center
}
var alignment:TextAlignment = TextAlignment.left

if alignment == .left {
    print("we should right-align the text!")
}


switch alignment {
case .left:
    print("left")
case .right:
    print("right")
default:
    print("center")
}


//原始值类型:给每个枚举的成员设置一个类型为Int的原始值，第一个原始值默认是0，以此类推。

enum TextAlignment1:Int{
    case left
    case right
    case center = 20
}
print("right:\(TextAlignment1.right.rawValue)")
print("right:\(TextAlignment1.center.rawValue)")

//原始值转换回枚举类型
let myAligment = TextAlignment1(rawValue: 20)
print("\(myAligment!)")

//原始值只能是整型？哈哈，这可是Swift。它的原始值支持一系列类型
enum ProgrammingLanguage:String
{
    case swift = "swift"
    case objectiveC = "objective-c"
    case c = "c"
}
let myFavoriteLanguage = ProgrammingLanguage.swift
print("\(myFavoriteLanguage.rawValue)")


//3.方法
//方法是和类型关联的函数。有些语言的方法，智能和类关联。但在swift中，方法还可以和枚举关联。
enum Lightbulb{
    case on
    case off
    
    func surfaceTemperature(forAmbientTemperature ambient:Double)->Double
    {
        switch self {
        case .on:
            return ambient + 150.0;
        case .off:
            return ambient
        }
    }
}
var bulb = Lightbulb.on
let ambientTemperature = 77.0
var bulbTemperature = bulb.surfaceTemperature(forAmbientTemperature: ambientTemperature)

//4.关联值
//关联值能让你把数据附在枚举实例上，不同的成员可以有不同类型的关联值
enum ShapeDimensions{
    //正方形的关联值是边长
    case oquare(side:Double)
    
    //长方形的关联值是长和宽
    case rectangle(width:Double,height:Double)
    
    func area() -> Double
    {
        switch self {
        case let .oquare(side: side):
            return side * side
        case let .rectangle(width: w, height: h):
            return w * h
        }
    }
}
var squareShape = ShapeDimensions.oquare(side: 4.0)
var rectShape = ShapeDimensions.rectangle(width: 5.0, height: 10.0)
print("oquare's area = \(squareShape.area())")
print("rectShape area = \(rectShape.area())")

//5.递归枚举

